const BaseController = require("../library/base-controller");
const Mapper = require("../database/mapper/anchor")
const {crud} = require("../library/crud")
const Services = require("ee-core/services");

// ee在注册路由时，没有遍历父类方法，所以这里不能把crud写在BaseController
class AnchorController extends BaseController{
    init() {
        this.mapper = new Mapper()
        /**
         * @type AnchorService
         * @var AnchorService
         */
        this.service = Services.get('anchor');
    }

    async scanf(params,e,ev){
        if(this.service.has(params.id)){
            return this.error("任务已存在，请不要重复创建")
        }
        this.service.scanf(params.id,params.channel, e.sender);
        return this.success('抢红包任务已启动')
    }

    async stop(params){
        if(!this.service.has(params.id)){
            return this.error("任务不存在！")
        }
        this.service.stop(params.id);
        return this.success()
    }
}

crud(AnchorController)

module.exports = AnchorController
